<template>
	<view class="third-body">
		<view @tap="openPopup" style="padding: 18upx 22upx;background: #26a2ff;">
			<view style="padding:0 20upx;color:#909399;font-size:15px;background-color: #fff;line-height: 56upx;border-radius:4px;">
				<label>地区：</label>
				{{AREA_NAME}}
			</view>

		</view>
		<scroll-view class="uni-scroll-view-list sec-uni-scroll-view-list" scroll-y lower-threshold="50" @scrolltolower="loadMore">

		<view class="sub-content">
			
			<uni-list class="my-list" v-if="hosArr.length">
				<uni-list-item v-for="(hos,hosIndex) in hosArr" :key="hosIndex" :title="hos.AKB021"   @click="hosTrigger(hos)"></uni-list-item>
			</uni-list>
			
			<uni-load-more v-if="hosArr.length" :status="status" :contentText="contentTxt"></uni-load-more>
			<view v-if="!hosArr.length" style="padding:100upx 16upx;text-align: center;">
				<image src="../../static/image/order.png" mode="widthFix" style="width:180upx;"></image>
			</view>
		</view>
		
		
		</scroll-view>
		<areaSelect ref="linkAddress" :initProvince="initProvince" :height="height" @confirmCallback="confirmCallback">
		</areaSelect>
	</view>
</template>

<script>
	import uniPopup from "@/components/uni-popup/uni-popup.vue";
	import uniList from '@/components/uni-list/uni-list.vue'
	import uniListItem from '@/components/uni-list-item/uni-list-item.vue'
    import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue'

	import uniTag from '@/components/uni-tag/uni-tag.vue';

	import areaSelect from '@/components/area-select/linkAddress.vue';

	export default {
		components: {
			uniPopup,
			uniTag,
			uniList,
			uniListItem,
			areaSelect,
			uniLoadMore
		},
		data() {

			return {
				initProvince:[],
				AREA_NAME: '', //就医地地区名称
				AKC801: '', //就医地地区代码
				AKB021: '', //就医地医院名称
				type: '',
				hosArr: [],
				height: '500px',
				pageIndex: 1,
				totalPage: 1,
				SNW_FLAGL:0,
				status: 'more',
				contentTxt: {
					contentdown: "查看更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多",
				},
				citySet: {
					defaultValue: [0, 0, 0]
				}
			}
		},
		computed: {
			allArr: function() {
				return [this.provinceArr, this.cityArr, this.areaArr, this.hosArr]
			}
		},
		methods: {
			//点击弹出弹窗
			openPopup: function() {
				this.height = '550rpx';
				//显示
				this.show_popup();

			},
			//显示弹窗
			show_popup: function() {
				this.$refs.linkAddress.show();
			},
			//回掉
			confirmCallback: function(select) {
				console.log(select)
				if(select){
					var index = select.length;
					this.AKC801 = select[index-1].AREA_CODE;
					this.AREA_NAME = select[index-1].AREA_NAME;
					this.getData(this.AKC801);
				}
				
				
			},
			loadMore(e) {
				if (this.pageIndex < this.totalPage) {
					this.pageIndex++;
					if (this.pageIndex > this.totalPage) {
						this.pageIndex = this.totalPage;
					}
					this.getData(this.AKC801);
			
				}
			},
			getData(areaCode) {
				var self = this;
				this.$request('S1007', {
					AKC801: areaCode,
					PAGENUM: this.pageIndex,
					PAGESIZE: 15
				}, 'POST', function(resList) {
					if (resList.data.CODE == '0' && resList.data.DATA.length) {
						self.totalPage = resList.data.PAGESIZECOUNT;
						
						self.hosArr = self.hosArr.concat(resList.data.DATA);
											
						if (self.pageIndex == self.totalPage) {
							self.status = 'noMore'
						} else {
							self.status = 'more'
						}
					}
				})
			},
			hosTrigger(item) {
				item['type'] = this.type
				uni.$emit('hosClick', item)
				// var pages = getCurrentPages();
				// var currPage = pages[pages.length - 1];   //当前页面
				// var prevPage = pages[pages.length - 2];  //上一个页面
				// console.info(pages)
				// //#ifdef H5
				// if(this.type=='out'){
				// 	prevPage._data.userInfo.ZCJGDM = item.AKC801
				// 	prevPage._data.userInfo.ZCJGMC = item.AKB021
				// }else{
				// 	prevPage._data.userInfo.ZWJGDM = item.AKC801
				// 	prevPage._data.userInfo.ZWJGMC = item.AKB021 
				// }
				// //#endif
				// //#ifdef APP-PLUS
				// if(this.type=='out'){
				// 	 prevPage.data.userInfo.ZCJGDM = item.AKC801
				// 	  prevPage.data.userInfo.ZCJGMC = item.AKC801
				// }else{
				// 	prevPage.data.userInfo.ZWJGDM = item.AKC801
				// 	 prevPage.data.userInfo.ZWJGMC = item.AKC801
				// }
				// //#endif
				uni.navigateBack()
				
			}
		},
		onLoad(param) {
			if (param.currentAreaCode) {
				this.currentAreaCode = param.currentAreaCode;
			}
			if (param.type) {
				this.type = param.type;
			}
			if(param.SNW_FLAG){
				this.SNW_FLAG =  param.SNW_FLAG;
				if(this.SNW_FLAG == 1 || this.type == 'out'){
					this.initProvince[0] = {AREA_CODE:'620000',AREA_NAME:'甘肃省'};
				}else{
					this.initProvince = [];
				}
			}


		}
	}
</script>

<style lang="scss">
	.sub-content {
		padding: 0upx 20upx 0upx 20upx;
	}

	.content {
		display: flex;
		justify-content: space-between;
		line-height: 70upx;
		padding: 0 30upx;
		font-size: 15px;
		border-top: 1px dashed #E4E7ED;
	}

	.content:first-child {
		border-top: none;
	}

	.uni-list-item {
		width: auto;
		margin-bottom: 10upx;
		font-size: 16px;
		color: #606266 !important;
		line-height: 30px;
	}
</style>
